package com.gitee.vueantd.system.config;

import com.gitee.vueantd.system.config.thread.ThreadPoolExecutorUtil;
import com.google.common.eventbus.AsyncEventBus;
import com.google.common.eventbus.EventBus;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.annotation.PreDestroy;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

@Configuration
public class EventBusConfig {
  private ExecutorService executorService = Executors.newFixedThreadPool(1);

  @Bean
  public EventBus eventBus() {
    return new AsyncEventBus(executorService);
  }

  @PreDestroy
  private void uninit() {
    ThreadPoolExecutorUtil.shutdown(executorService);
  }
}
